import test from "uview-ui/libs/function/test";

export default {
    namespaced: true,
    state: {
      cartList: uni.getStorageSync('cartList') || []
    },
    mutations:{
        getCartList(state,newVal){
		  state.cartList = newVal
		  uni.setStorageSync('cartList',newVal)
		}
    },
    actions: {

    },
    getters: {
		isAllSelected(state) {
			return state.cartList.every(item => item.selected);
		},
		price(state){
			return state.cartList.reduce((pre,item) => {
				if(item.selected){
					pre += item.skuPrice * item.count
				}
                console.log(pre)
				return pre
			},0)
		},
		count(state){
			return state.cartList.reduce((pre,item) => {
				if(item.selected){
					pre += item.count
				}
				return pre
			},0)
		},
		selectedCartList(state) {
			return state.cartList.filter(item => item.selected);
		},
        allCount(state){
            return state.cartList.reduce((pre,item) => {
				pre += item.count
                if(pre >=99){
                  pre = 99
                }
				return pre
			},0)
        }
	},
}